//package com.thinta.wind.ui.home.adapter
//
//import android.view.LayoutInflater
//import android.view.View
//import android.view.ViewGroup
//import androidx.databinding.DataBindingUtil
//import androidx.databinding.ViewDataBinding
//import androidx.paging.PagedListAdapter
//import androidx.recyclerview.widget.DiffUtil
//import androidx.recyclerview.widget.RecyclerView
//import com.stx.xhb.androidx.XBanner
//import com.thinta.wind.R
//import com.thinta.wind.base.BasePagedListAdapterObserver
//import com.thinta.wind.databinding.*
//import com.thinta.wind.entity.HomeRecommendItemListBean
//import com.thinta.wind.entity.RecommendBannerItem
//import com.thinta.wind.interfaces.OnItemClickListener
//
///*********************************************************
// * 版权信息：2021/5/25 17:10北京振中电子技术有限公司版权所有<p>
// * 创建作者：Wind<p>
// * 创建日期：2021/5/25 17:10<p>
// * *******************************************************<p>
// * 更新历史：    作者      日期      更新摘要<p>
// * <p>
// * *******************************************************<p>
// * 类功能说明：<p>
// */
//class RecommendAdapter : PagedListAdapter<HomeRecommendItemListBean, RecyclerView.ViewHolder>(diffCallback){
//
//    var isLoadMore = 3
//    private lateinit var itemListener : OnItemClickListener
//    private lateinit var itemBannerListener : OnItemClickListener
//    private var bannerData : List<RecommendBannerItem>? = null
//
//    fun setOnItemClickListener(itemListener : OnItemClickListener){
//        this.itemListener = itemListener
//    }
//
//    fun setOnBannerClickListener(itemBannerListener : OnItemClickListener){
//        this.itemBannerListener = itemBannerListener
//    }
//
//    fun setBannerData(bannerData : List<RecommendBannerItem>){
//        this.bannerData = bannerData
//    }
//
//    override fun getItemViewType(position: Int): Int =
//        when(position){
//            0 -> ITEM_TYPE_HEADER
//            itemCount - 1 -> ITEM_TYPE_FOOTER
//            else -> super.getItemViewType(position)
//        }
//
//    override fun getItemCount(): Int = super.getItemCount() + 2
//
//    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
//        when(holder){
//            is RecommendHeaderView -> if(bannerData != null) holder.bindHeaderData(bannerData!!, itemBannerListener)
//            is RecommendViewHolder -> holder.bindItemData(getItem(position - 1)!!, itemListener)
//            is RecommendFooterView -> holder.bindFooterData(isLoadMore)
//        }
//    }
//
//    override fun registerAdapterDataObserver(observer: RecyclerView.AdapterDataObserver) {
//        super.registerAdapterDataObserver(BasePagedListAdapterObserver(observer, 1))
//    }
//
//    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder =
//        when(viewType){
//            ITEM_TYPE_HEADER -> RecommendHeaderView(parent)
//            ITEM_TYPE_FOOTER -> RecommendFooterView(parent)
//            else -> RecommendViewHolder(parent)
//        }
//
//    companion object {
//        private const val ITEM_TYPE_HEADER = 99
//        private const val ITEM_TYPE_FOOTER = 100
//
//        private val diffCallback = object : DiffUtil.ItemCallback<HomeRecommendItemListBean>() {
//            override fun areItemsTheSame(oldItem: HomeRecommendItemListBean, newItem: HomeRecommendItemListBean): Boolean =
//                oldItem.id == newItem.id
//            override fun areContentsTheSame(oldItem: HomeRecommendItemListBean, newItem: HomeRecommendItemListBean): Boolean =
//                oldItem == newItem
//        }
//    }
//}
//
//class RecommendFooterView(parent: ViewGroup) : RecyclerView.ViewHolder(LayoutInflater.from(parent.context).inflate(
//    R.layout.follow_footer_view, parent, false)){
//
//    private lateinit var mFooterBinding : RecommendFooterViewBinding
//
//    fun bindFooterData(isLoadMore: Int){
//        mFooterBinding = initViewBinding(itemView) as RecommendFooterViewBinding
//        when(isLoadMore){
//            1 -> mFooterBinding.footerContent.text = ""
//            2 -> mFooterBinding.footerContent.text = mFooterBinding.root.resources.getString(R.string.loading)
//            3 -> mFooterBinding.footerContent.text = mFooterBinding.root.resources.getString(R.string.not_more)
//        }
//    }
//
//}
//
//class RecommendHeaderView(parent: ViewGroup) : RecyclerView.ViewHolder(LayoutInflater.from(parent.context).inflate(
//    R.layout.follow_header_view, parent, false)){
//
//    private lateinit var mHeaderBinding : RecommendHeaderViewBinding
//    private lateinit var mBannerBinding : FollowBannerViewBinding
//
//
//    fun bindHeaderData(data: List<RecommendBannerItem>, listener: OnItemClickListener){
//        mHeaderBinding = initViewBinding(itemView) as RecommendHeaderViewBinding
//        mHeaderBinding.headerPager.setBannerData(R.layout.follow_banner_view, data)
//        mHeaderBinding.headerPager.loadImage(mAdapter)
//        mHeaderBinding.headerTitle.text = mHeaderBinding.root.resources.getString(R.string.home_recommend_wonderful)
//        mHeaderBinding.headerPager.setOnItemClickListener { _, _, view, position ->
//            listener.onItemClick(position, view)
//        }
//    }
//
//    private fun getBannerAdapter() : XBanner.XBannerAdapter = XBanner.XBannerAdapter {
//            _, model, view, _ ->
//        mBannerBinding = initViewBinding(view) as RecommendBannerViewBinding
//        mBannerBinding.bannerItem = model as RecommendBannerItem
//    }
//
//}
//
//class RecommendViewHolder(parent: ViewGroup) : RecyclerView.ViewHolder(LayoutInflater.from(parent.context).inflate(
//    R.layout.follow_content_item_view, parent, false)){
//
//    private lateinit var mBinding : RecommendContentItemViewBinding
//
//    fun bindItemData(data: HomeRecommendItemListBean, listener: OnItemClickListener){
//        mBinding = initViewBinding(itemView) as RecommendContentItemViewBinding
//        mBinding.itemTitle.visibility = View.GONE
//        mBinding.themeHeaderLayout.visibility = View.GONE
//        mBinding.themeLayout.visibility = View.GONE
//        when{
//            data.type.equals("textCard", true) -> mBinding.itemTitle.visibility = View.VISIBLE
//            data.type.equals("followCard", true) -> mBinding.themeHeaderLayout.visibility = View.VISIBLE
//            data.type.equals("videoSmallCard", true) -> mBinding.themeLayout.visibility = View.VISIBLE
//        }
//        mBinding.item = data
//        mBinding.root.setOnClickListener {
//            listener.onItemClick(layoutPosition, it)
//        }
//    }
//
//}
//
//private fun initViewBinding(itemView : View) : ViewDataBinding? =
//    if (null == DataBindingUtil.getBinding(itemView)) {
//        DataBindingUtil.bind(itemView)
//    } else {
//        DataBindingUtil.getBinding(itemView)
//    }
